﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using GameListCreator.ViewModels;

namespace GameListCreator.Controls
{
    /// <summary>
    /// Interaction logic for GameSelector.xaml
    /// </summary>
    public partial class GameSelector : UserControl
    {
        /// <summary>
        /// Constructeur
        /// </summary>

        public GameSelector()
        {
            InitializeComponent();

           this.LayoutRoot.DataContext = App.GameListViewModel;
        }

        /// <summary>
        /// TextBox Search
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

        private void TextBoxSearch_TextChanged(object sender, TextChangedEventArgs e)
        {
            TextBox textBox = sender as TextBox;
            App.GameListViewModel.Filter = textBox.Text;
        }

        /// <summary>
        /// Ajouter un jeu
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

        private void ButtonAdd_Click(object sender, RoutedEventArgs e)
        {
            App.GameListViewModel.AddGame("GameBoy");
        }

        /// <summary>
        /// Retirer un jeu
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

        private void ButtonRemove_Click(object sender, RoutedEventArgs e)
        {
            App.GameListViewModel.RemoveGame();
        }

        /// <summary>
        /// Drop
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

        private void LayoutRoot_Drop(object sender, DragEventArgs e)
        {
            GameViewModel game = App.GameListViewModel.CreateGame("GameBoy");


            if (GameEditor.Instance.DropData(e, game) == true)
            {
                App.GameListViewModel.AddGame(game);
            }
        }
    }
}
